#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int a[N];
int lowbit(int x) { return x & -x; }
vector<int> cut(int l, int r) {
  vector<int> res;
  if (l) {
    int d = lowbit(l);
    while (l + d <= r) {
      res.push_back(d);
      l += d;
      d = lowbit(l);
    }
  }
  r -= l;
  rep(i, 0, 20) if (r & (1 << i)) res.push_back(1 << i);
  return res;
}
ll f(int x1, int x2, int y1, int y2) {
  vector<int> d1 = cut(x1, x2);
  vector<int> d2 = cut(y1, y2);
  ll sum = 0;
  for (int x : d1)
    for (int y : d2) {
      int mn = min(x, y);
      int mx = max(x, y);
      sum += mx / mn;
    }
  return sum;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int x1, x2, y1, y2;
    cin >> x1 >> x2 >> y1 >> y2;
    cout << f(x1, x2, y1, y2) << endl;
  }
  return 0;
}